﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IllustratedCsharp7_ch21
{
    class Chapt21_3AsyncMethodEx2_ReutrnTask_Object
    {
        static void _Main()
        {
            Task sometask = DoAsyncStuff.CalculateSumAsync(5, 6);
            //处理其他事情

            sometask.Wait();           
            Console.WriteLine("Async stuff is done");
        }
    }

    static class DoAsyncStuff
    {
        //使用返回Task对象的异步方法
        public static async Task CalculateSumAsync(int i1, int i2)
        {
            int value = await Task.Run(() => GetSum(i1, i2));
            Console.WriteLine("Value{0}:", value);           
        }
        private static int GetSum(int i1, int i2) { return i1 + i2; }
    }
}
